
dfly.ModuleModel = function(properties) {
  for (var p in properties) {
    this[p] = properties[p];
  }
};

dfly.ModuleModel.get = function(moduleName) {
    var results = [];
    
    var jsConnectionObj = new Packages.JsConnection();
    c = jsConnectionObj.open(DATABASE[ENVIRONMENT].host,
                             DATABASE[ENVIRONMENT].database,
                             DATABASE[ENVIRONMENT].username,
                             DATABASE[ENVIRONMENT].password);
 
    if (c) {
      var s = c.createStatement();
      s.executeQuery("SELECT * FROM modules where path='"+moduleName+"';");
      var rs = s.getResultSet();
      while (rs.next()) {
         var def = rs.getString("definition");
         var definition = null;
         if(!!def && def != "") {
            definition = eval('('+def+')');
         }
          results.push(new ModuleModel({
            path: rs.getString("path"),
            parameters: eval('('+rs.getString("parameters")+')'),
            definition: definition
          }));
      }
      rs.close();
      c.close();  
      return results[0];
    }

    throw new Error('could not connect to database');      
};

